#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QThread>
#include <QTimer>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    m_systemMonitor = new SystemMonitor();
    connect(m_systemMonitor, &SystemMonitor::online, this, &MainWindow::onOnline);
    connect(m_systemMonitor,  &SystemMonitor::offline,  this, &MainWindow::onOffline);
    connect(m_systemMonitor,  &SystemMonitor::wake,  this, &MainWindow::onWake);
    connect(m_systemMonitor,  &SystemMonitor::sleep,  this, &MainWindow::onSleep);
    connect(m_systemMonitor,  &SystemMonitor::screenLocked,  this, &MainWindow::onScreenLocked);
    connect(m_systemMonitor,  &SystemMonitor::screenUnlocked,  this, &MainWindow::onScreenUnlocked);
    connect(m_systemMonitor,  &SystemMonitor::screenSaverStarted,  this, &MainWindow::onScreenSaverStarted);
    connect(m_systemMonitor,  &SystemMonitor::screenSaverStopped,  this, &MainWindow::onScreenSaverStopped);
}

MainWindow::~MainWindow()
{
    if(m_systemMonitor)
        m_systemMonitor->deleteLater();
    delete ui;
}



void MainWindow::onWake()
{
     ui->textEdit->append("net work is wake!");
}

void MainWindow::onSleep()
{
    ui->textEdit->append("net work is sleep!");
}

void MainWindow::onOnline()
{
    ui->textEdit->append("computer is online!");
}

void MainWindow::onOffline()
{
    ui->textEdit->append("computer is offline!");
}

void MainWindow::onScreenLocked()
{
     ui->textEdit->append("computer is screenLocked!");
}

void MainWindow::onScreenUnlocked()
{
    ui->textEdit->append("computer is screenUnlocked!");
}

void MainWindow::onScreenSaverStarted()
{
    ui->textEdit->append("computer is screenSaverStarted!");
}

void MainWindow::onScreenSaverStopped()
{
    ui->textEdit->append("computer is screenSaverStopped!");
}
